package com.zlp.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zlp.common.utils.ExcelUtils;
import com.zlp.common.utils.SheetData;
import com.zlp.common.utils.TestData;

@Controller
public class HelloController {
	
	 
    @RequestMapping(value="/login")
    public String hello(){
        return "login";
    }
    
    @RequestMapping("/exportExcelPlatform")
	public void exportExcelPlatform(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> paramMap) {
		try {
//			new ExportExcelUtil().exportExcel(dataList, response);
			  //获取模板   
	    	String exceltempPath ="/test.xlsx";
	        File f = new File("e:/carte.xlsx");


	        SheetData[] sds = new SheetData[1];  
	          
	        //创建1个数据sheet  
	        for( int i = 0 ; i < 1 ; i++) {  
	            SheetData sd = new SheetData("测试" + i);  // sheet 标题
	            sd.put("name", "张三" + i);  
	            sd.put("age", 13);  
	              
	            //每个sheet页加入100条测试数据  
	            //注意这里可以加入pojo也可以直接使用map,理论上map在这里效率更高一些  
	            for(int j = 0 ; j < 6 ; j++) {  
//	                TestData td = new TestData(j, j * -1, "t" + j);  
	                Map<String, Object> map = new HashMap<>();
	                map.put("name", "张三"+j);
	                map.put("upMonth", "upMonth"+j);
	                map.put("thisMonth", "thisMonth"+j);
	                map.put("thisDay", "thisDay"+j);
	                sd.addData(map); 
	            }  
	               
	            sds[i] = sd ;  
	        }  
	           
			ExcelUtils.writeData(exceltempPath, new FileOutputStream(f),response,sds);  
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
